package com.sike.netty.jinjie.channelhandler.sharable;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicInteger;

@Slf4j
@ChannelHandler.Sharable
public class SharableTestHandler extends ChannelInboundHandlerAdapter {
    /**
     * 计数器
     * 需要考虑线程安全
     */
    private Integer count = 1;


    @Override
    public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
        synchronized (this) {
            log.info("一共有[" + count++ + "]客户端已建立连接..");
        }
    }
}
